package com.briup.run.web.servlet;

import com.briup.run.service.MemberInfoService;
import com.briup.run.service.impl.MemberInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Auther: vanse(lc))
 * @Date: 2022/10/11-10-11-15:17
 * @Description：${PACKAGE_NAME}
 */
@WebServlet("/foundPass")
public class FoundPassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 接收信息
        String userName = request.getParameter("userName");
        String passwdQuestion = request.getParameter("passwdQuestion");
        String passwdAnswer = request.getParameter("passwdAnswer");
        // service核对信息
        MemberInfoService memberInfoService = new MemberInfoServiceImpl();
        HttpSession session = request.getSession();
        String url = "login.jsp";
        String msg = "新密码已发送到邮箱,请查验";
        try {
            // 正确 重定向
            memberInfoService.foundPass(userName,passwdQuestion,passwdAnswer);
        } catch (Exception e) {
            e.printStackTrace();
            url = "passwd_missing.jsp";
            msg = e.getMessage();
        }
        // 错误 当前页面
        session.setAttribute("error",msg);
        response.sendRedirect(url);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

